#include <iostream>
#include <vector>
#include <string>

using namespace std;

int addDigits(int num) {
    while(num > 9){
        int d = 0;
        while(num != 0){
            d += num % 10;
            num /= 10;
        }
        num = d;
    }
    return num;
}

int main(){
    int num = 38;
    cout << addDigits(num) << endl;
    return 0;
}
